package org.example.java.socket.date;

import javax.swing.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

/**
 * User: ZhangJuntao
 * Date: 14-2-11
 * Time: 上午10:46
 */
public class DateClient {
  /**
   * Runs the client as an application.  First it displays a dialog
   * box asking for the IP address or hostname of a host running
   * the date server, then connects to it and displays the date that
   * it serves.
   */
  public static void main(String[] args) throws IOException {
    String serverAddress = JOptionPane.showInputDialog(
        "Enter IP Address of a machine that is\n" +
            "running the date service on port 9090:");
    Socket s = new Socket(serverAddress, 19090);
    BufferedReader input =
        new BufferedReader(new InputStreamReader(s.getInputStream()));
    String answer = input.readLine();
    JOptionPane.showMessageDialog(null, answer);
    System.exit(0);
  }
}
